﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.payment {
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.models.world.vos.actors.machines.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.utils.*;
    import net.wooga.pets.models.fountain.*;
    import net.wooga.pets.models.kiosk.*;
    import net.wooga.pets.models.world.*;

    public class PlaceOrderSuccessCommand extends Command {

        public var event:InfoEvent;
        public var energy:EnergyModel;
        public var symbols:SymbolModel;
        public var world:WorldModel;
        public var payment:PaymentModel;
        public var user:UserModel;
        public var roomSlotsModel:RoomSlotsModel;
        public var inventory:InventoryModel;
        public var kiosk:KioskModel;

        override public function execute():void{
            var _local1:Array = (this.event.info as Array);
            var _local2:Object = _local1.shift();
            this.closePopup(_local2.product_type);
            switch (_local2.product_type){
                case ProtocolConstants.BUY_GEMS:
                    this.handleGems(_local2);
                    break;
                case ProtocolConstants.BUY_BOOSTS:
                    this.handleBoosts(_local2);
                    break;
                case ProtocolConstants.BUY_ROOM_SLOT:
                    this.handleRoomSlots(_local2);
                    break;
                case ProtocolConstants.BUY_GOODS:
                    this.handleGoods(_local2);
                    break;
                case ProtocolConstants.BUY_CRAFT_ITEMS:
                    this.handleCraftItems(_local2);
                    break;
                case ProtocolConstants.BUY_ADOPT:
                    this.handleBuyAdopt(_local2);
                    break;
            };
        }
        private function closePopup(_arg1:String):void{
            var _local2:InfoEvent = new InfoEvent(EventConstants.CLOSE_POPUP_BY_TYPE, _arg1);
            dispatch(_local2);
        }
        private function handleBoosts(_arg1:Object):void{
            this.energy.refill(_arg1.amount);
        }
        private function handleRoomSlots(_arg1:Object):void{
            this.roomSlotsModel.availableRoomSlotsNumber++;
            dispatch(new UserModelEvent(UserModelEvent.ON_MODEL_CHANGED));
        }
        private function handleGoods(_arg1:Object):void{
            this.user.goods = (this.user.goods + _arg1.amount);
            dispatch(new UserModelEvent(UserModelEvent.ON_MODEL_CHANGED));
            var _local2:Object = {type:"order", st1:"credits", st2:_arg1.amount, st3:0};
            dispatch(new TrackingEvent(TrackingConst.TRACK, TrackingConst.GOODS, _local2));
        }
        private function handleGems(_arg1:Object):void{
            var _local2:Array = (this.payment.getData(ProtocolConstants.BUY_GEMS) as Array);
            var _local3:Object = Arrays.findByAttribute(_local2, "name", ProtocolConstants.INSTANT_FOUNTAIN_START);
            if (_arg1.product_id == _local3.product_id){
                this.fillUpGems();
            };
        }
        private function handleCraftItems(_arg1:Object):void{
            dispatch(new InfoEvent(EventConstants.GET_ROOM_ITEMS, _arg1.roomId));
            dispatch(new InfoEvent(EventConstants.PLAY_KIOSK_BUY_ANIMATION, _arg1.itemCode));
        }
        private function fillUpGems():void{
            this.symbols.fillUp(this.fountain.patient.currentTreatment.symbols);
            var _local1:InfoEvent = this.fountain.createSymbolCollectionWindow();
            dispatch(_local1);
        }
        private function handleBuyAdopt(_arg1:Object):void{
            this.closePopup(GameConstants.ADOPT_POPUP);
            dispatch(new InfoEvent(EventConstants.UPDATE_AND_SHOW_POPUP, GameConstants.ADOPT_POPUP, {id:_arg1.entity_id}));
        }
        private function get fountain():FountainMachineVO{
            var _local1:Array = this.world.getRoomIdsOfType(GameConstants.TYPE_FOUNTAIN);
            var _local2:FountainMachineVO = (IRoom(this.world.getRoomById(_local1[0])).machine as FountainMachineVO);
            return (_local2);
        }

    }
}//package net.wooga.pets.controllers.payment 
